(function(angular) {
	'use strict';
	angular.module('fs.waf').controller('apf.popup.discount.discChargeDetail', discChargeDetailController);
	discChargeDetailController.$inject = [ '$scope', '$q', '$uibModalInstance', 'Constants', 'ajaxServiceFactory', 'dialogsModule', 'gridService', 'modalService', 'layoutConfig', 'validatorConfig', 'authService' ];
	function discChargeDetailController($scope, $q, $uibModalInstance, Constants, ajaxServiceFactory, dialogsModule, gridService, modalService, layoutConfig, validatorConfig, authService) {
		var ctrl = this, ajaxService = ajaxServiceFactory.buildAjaxService({
			getIntCollMethodOptions : {
				url : 'do/cda/dataList/intCollMethods',
				method : 'get'
			},
		});
		ctrl.dialogsModule = dialogsModule;
		ctrl.layoutConfig = layoutConfig;
		ctrl.validatorConfig = validatorConfig;
		ctrl.discChargeDetai = {};
		
		ctrl.init = function() {
			getIntCollMethodOptions().then(function(response){
				ctrl.calcMethodOptions = response.data;
				ctrl.discChargeDetai = dialogsModule.params.disCountDetail;
				ctrl.discChargeDetai.loanCcy = dialogsModule.params.loanCcy;
			});
		};
		
		function getIntCollMethodOptions() {
			var defer = $q.defer();
			ajaxService.getIntCollMethodOptions().then(function(response) {
				defer.resolve(response ? response : {});
			});
			return defer.promise;
		};
		
		ctrl.ok = function() {
			if (!dialogsModule.btnCallback || !dialogsModule.btnCallback['ok'] || dialogsModule.btnCallback['ok']() !== false) {
				$uibModalInstance.close();
			}
		};
		
		ctrl.close = function() {
			if (!dialogsModule.btnCallback || !dialogsModule.btnCallback['close'] || dialogsModule.btnCallback['close']() !== false) {
				$uibModalInstance.dismiss();
			}
		};
	}
})(angular);
